package com.gonsin.gview.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gonsin.gview.annotations.GContext;
import com.gonsin.gview.model.i18n.TCloneable;
import com.gonsin.i18n.logic.T;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@ApiModel("页面模板总结构")
public class GViewModel implements TCloneable<GViewModel> {

    @ApiModelProperty("页面名字，必须唯一，跳转页面时需要用到")
    private String viewName;

    @ApiModelProperty("页面标题")
    private String title;

    @ApiModelProperty("该页面所需的参数")
    private List<String> props;

    @ApiModelProperty("页面所拥有的board")
    private List<GBoardModel> boards;

    @ApiModelProperty("后台传入的props")
    private Map<String, Object> serverProps;

    @JsonIgnore
    private transient GContext context;

    @Override
    public GViewModel tClone()  {
        GViewModel model = new GViewModel();
        model.setViewName(this.viewName);
        if(title != null){
            model.setTitle(T.t(this.title));
        }
        model.setProps(this.props);
        model.setServerProps(this.serverProps);
        if(boards != null){
            model.boards = new ArrayList<>();
            for(GBoardModel origin : boards){
                model.boards.add(origin.tClone());
            }
        }
        model.context = context;
        return model;
    }
}
